<template>
	<view class="pages">
		<view class="cell-group_warp">
			<u--form labelPosition="left" :model="formData" :rules="rules" ref="uForm">
				<view class="cell-group u-border-radius">
					<u-form-item label="" :prop="item.fieldName" v-for="item in information_list">
						<!-- v-if="item.is_show!=true"/ -->

						<yy-cell-v2 v-model="formData[item.fieldName]" ref="child" @change_list="change_list"
							:config='item' v-if="item.modality">
						</yy-cell-v2>

						<yy-uploadpictures :config='item' v-model="formData[item.fieldName]" v-else></yy-uploadpictures>
					</u-form-item>
				</view>
				<!-- <view v-else-if="(current==3||current==4)&&isShowArr">
					<u-form-item label="" :prop="item.fieldName" v-for="item in information_list"
						v-if="current==item.id&&(item.fieldName=='frontalView'||item.fieldName=='idPhoto')">
						<yy-uploadpictures :config='item' v-model="formData[item.fieldName]"></yy-uploadpictures>
					</u-form-item>
				</view> -->
			</u--form>
			<view class="next" @click="submit">
				<text>提交</text>
			</view>
			<!-- <u-popup :show="modal_show" @close="modal_show=false" mode="center" :round='20' :safeAreaInsetBottom="safeAreaInsetBottom">
				<view class="modal u-flex-column u-flex-between">
					<text class="modal_title">{{title}}</text>
					<view class="moda_content">
						<text>资料{{status==0?'审核中，请耐心等待':'已通过'}}</text>
						<text>请将您的ID:{{id}}告知红娘</text>
					</view>
					<view class="u-flex-x-center u-flex-between">
						<view class="modalbtn modalbtn_left" @click="copy">
							<text>复制ID</text>
						</view>
						<view class="modalbtn modalbtn_right" @click="modal_show=false;return_home()">
							<text>关闭</text>
						</view>
					</view>
				</view>
			</u-popup> -->
		</view>
	</view>
</template>

<script>
	import {
		matchmakingData,
	} from '@/util/Invite_matchmaker.js'
	import {
		getDeputyBasicInfo,
		deputyBasicInfo,
		editDeputyBasicInfo
	} from '@/common/api.js'
	const app = getApp()
	export default {
		data() {
			return {
				information_list: matchmakingData.fieldName_list,
				rules: {

				},
				type:'',
				userId: '',
				formData: {
					//matchUserId: '', //红娘用户id
					fullName: '', //姓名
					phone: "", //联系方式
					homeAddress: '', //家庭住址
					storeAddress: '', //门店住址
					idCard: '[]', //身份证正面
					// idCardSide:'',
					businessLicense: '[]', //营业执照
					storeGroupPhoto: '[]', //店铺和本人合照
					agreement: '[]' //合同照片
				}
			}
		},
		watch: {
			formData: {
				handler(value) {
					// console.log('深度监听', value)
					// try {
					// 	uni.setStorageSync('agency_info', this.formData)
					// } catch (e) {
					// }
				},
				deep: true // 深度监听
			},
		},
		async onLoad(option) {
			if (option.userId) {
				this.userId = option.userId
			}
			if(option.type){
				this.type=option.type
			}
			if (uni.getStorageSync('access_token')) {
				let {
					userId
				} = uni.getStorageSync('user_info')
				if (option.type == '编辑') {
					
					if (uni.getStorageSync('agency_info')) {
						this.formData = uni.getStorageSync('agency_info')
					} else {
						let BasicInfo = await this.get_DeputyBasicInfo()
						this.formData = BasicInfo
					}
				}
				this.$wxShare(0)
			} else {
				uni.navigateTo({
					url: '/pages/guide/index'
				})
			}

		},
		onShow() {


		},
		methods: {
			get_DeputyBasicInfo() {
				let data = {
					params: {
						userId: this.userId
					}
				}
				return new Promise(resolve => {
					getDeputyBasicInfo(data, {
						custom: {
							auth: true,
							toast: false,
							catch: true
						}
					}).then((result) => {
						resolve(result)
					}).catch((err) => {
						reject(err)
					})

				})
			},
			return_beforpage(){
				var pages = getCurrentPages(); //当前页
				var beforePage = pages[pages.length - 2]; //上个页面
				
				// #ifdef H5
				beforePage.init()
				// #endif
				// #ifndef H5
				beforePage.$vm.init()
				// #endif
				setTimeout(() => {
					uni.navigateBack()
				}, 500)
			},
			submit() {
				let isclick = true
				if (isclick) {
					isclick = false
					uni.showLoading({
						title: '加载中'
					});
					console.log(this.type)
					if(this.type=='编辑'){
						editDeputyBasicInfo(this.formData, {
							custom: {
								auth: true,
								toast: false,
								catch: true
							}
						}).then((result) => {
						
							if (result.code == 2) {
								this.$Cmessage({
									showModel: true,
									confirmText: '我知道了',
									showCancel: false,
									content: result.massage,
									maskcloseAble: true
								}, {
									//确认
									emitBtn() {
										
									},
									//取消
									emitClose() {
										console.log('用户点击取消');
									},
								});
							} else {
								this.return_beforpage()
							}
							isclick = true
							uni.hideLoading()
							try {
								uni.removeStorageSync('agency_info')
							} catch (e) {
								//TODO handle the exception
							}
						}).catch((err) => {
							isclick = true
							uni.hideLoading()
							uni.hideLoading()
						})
					}else{
						deputyBasicInfo(this.formData, {
							custom: {
								auth: true,
								toast: false,
								catch: true
							}
						}).then((result) => {
						
							if (result.code == 2) {
								this.$Cmessage({
									showModel: true,
									confirmText: '我知道了',
									showCancel: false,
									content: result.massage,
									maskcloseAble: true
								}, {
									//确认
									emitBtn() {
										
									},
									//取消
									emitClose() {
										console.log('用户点击取消');
									},
								});
							} else {
								this.return_beforpage()
							}
							isclick = true
							uni.hideLoading()
							try {
								uni.removeStorageSync('agency_info')
							} catch (e) {
								//TODO handle the exception
							}
						}).catch((err) => {
							isclick = true
							uni.hideLoading()
							uni.hideLoading()
						})
					}
					
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		padding: 20rpx 24rpx 0;
		box-sizing: border-box;

		/deep/ .u-form-item__body {
			padding: 0 0 20rpx;
		}

		/deep/ .main {
			margin-bottom: 0rpx
		}

		.next {
			width: 100%;
			height: 92rpx;
			background: #FF7612;
			border-radius: 46rpx;
			color: #fff;
			text-align: center;
			line-height: 92rpx;
			margin: auto;
			box-sizing: border-box;

			text {
				font-size: 28rpx;
			}
		}

	}
</style>
